package org.shangrila.app.wechat.utils;

import org.json.JSONException;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

/**
 * Created by Administrator on 2018/1/18.
 */

public class JSONObjectUtil{

    public static JsonArray getJSONArray(JsonObject json, String name) throws JSONException {
        if(json.get(name)==null){
            return new JsonArray();
        }else{
            return json.getAsJsonArray(name);
        }
    }

    public static String getAsString(JsonObject jsonObject,String name){
        if(jsonObject.get(name)==null){
            return "";
        }else if(jsonObject.get(name).isJsonNull()){
            return "";
        }else{
            return jsonObject.get(name).getAsString();
        }
    }

    public static int getAsInt(JsonObject jsonObject,String name){
        if(jsonObject.get(name)==null){
            return -100;
        }else if(jsonObject.get(name).isJsonNull()){
            return -100;
        }else{
            return jsonObject.get(name).getAsInt();
        }
    }
}
